package Controlador;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import Modelo.mProductos;
import Modelo.mVentas;

public class cVenta {
	public void limpiar(JLabel jLabel6,JTextField jTextField1,JTextField jTextField2,JTextField jTextField3,JTextField jTextField4,JComboBox jComboBox1,JButton jButton1,JButton jButton2,JButton jButton3)
	{
		jLabel6.setVisible(false);
		jTextField1.setText("");
		jComboBox1.setSelectedItem(0);
		jTextField2.setText("");
		jTextField3.setText("");
		jTextField4.setText("");
		jLabel6.setText("jLabel6");
		jButton1.setEnabled(false);
		jButton2.setEnabled(false);
		jButton3.setEnabled(false);	
		jTextField1.setEnabled(true);
	}
	public void guardar(JLabel jLabel6,JTextField jTextField1,JTextField jTextField2,JTextField jTextField3,JTextField jTextField4,JComboBox jComboBox1,JButton jButton1,JButton jButton2,JButton jButton3)
	{
		mVentas tVentas = new mVentas();
		tVentas.setCodVenta(Integer.parseInt(jTextField1.getText()));
		tVentas.setCodProd(Integer.parseInt(jLabel6.getText()));
		tVentas.setCantidad(Integer.parseInt(jTextField2.getText()));
		tVentas.setMonto(Float.parseFloat(jTextField3.getText()));
		tVentas.setCliente(jTextField4.getText());
		tVentas.guardar();
		JOptionPane.showMessageDialog(null, "Actualizacion Completa");
		limpiar(jLabel6,jTextField1,jTextField2,jTextField3,jTextField4,jComboBox1,jButton1,jButton2,jButton3);
	}
	public void mostrar(mVentas t,JLabel jLabel6,JTextField jTextField1,JTextField jTextField2,JTextField jTextField3,JTextField jTextField4,JComboBox jComboBox1,JButton jButton1,JButton jButton2,JButton jButton3)
	{
		jTextField1.setText(""+t.getCodVenta());
		jLabel6.setText(""+t.getCodProd());
		jTextField2.setText(""+t.getCantidad());
		mProductos tProductos= new mProductos();
		tProductos.Cargar("\"CodProd\"="+ jLabel6.getText());
		jComboBox1.setSelectedItem(tProductos.getDescripcion());
		jTextField3.setText(""+t.getMonto());
		jTextField4.setText(""+t.getCliente());
		jButton1.setEnabled(false);
		jButton2.setEnabled(true);
		jButton3.setEnabled(true);	
		jTextField1.setEnabled(false);

	}
	public void buscar(mVentas t,JLabel jLabel6,JTextField jTextField1,JTextField jTextField2,JTextField jTextField3,JTextField jTextField4,JComboBox jComboBox1,JButton jButton1,JButton jButton2,JButton jButton3)
	{
		mVentas tVentas = new mVentas();
		tVentas.Cargar("\"CodVenta\"="+jTextField1.getText()+" ");
		if (tVentas.getEncontro())
			mostrar(tVentas,jLabel6,jTextField1,jTextField2,jTextField3,jTextField4,jComboBox1,jButton1,jButton2,jButton3);
		else
		{
			String aux=jTextField1.getText();
			limpiar(jLabel6,jTextField1,jTextField2,jTextField3,jTextField4,jComboBox1,jButton1,jButton2,jButton3);
			jTextField1.setText(aux);
			jButton1.setEnabled(true);
		}

	}
	public void eliminar(JLabel jLabel6,JTextField jTextField1,JTextField jTextField2,JTextField jTextField3,JTextField jTextField4,JComboBox jComboBox1,JButton jButton1,JButton jButton2,JButton jButton3)
	{
		if (JOptionPane.showConfirmDialog(null, "Esta seguro")==JOptionPane.YES_OPTION)
		{
			mVentas tVentas = new mVentas();			
			tVentas.Eliminar("\"CodVenta\"="+jTextField1.getText()+"");
			JOptionPane.showMessageDialog(null, "Eliminado");
			limpiar(jLabel6,jTextField1,jTextField2,jTextField3,jTextField4,jComboBox1,jButton1,jButton2,jButton3);
		}
	}
}
